package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysGeneralnaireRecord;
import com.ruoyi.system.service.ISysGeneralnaireRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 普查结果Controller
 * 
 * @author ruoyi
 * @date 2022-05-11
 */
@RestController
@RequestMapping("/system/generalsurveyrecord")
public class SysGeneralnaireRecordController extends BaseController
{
    @Autowired
    private ISysGeneralnaireRecordService sysGeneralnaireRecordService;

    /**
     * 查询普查结果列表
     */
   // @PreAuthorize("@ss.hasPermi('system:generalsurveyrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysGeneralnaireRecord sysGeneralnaireRecord)
    {
        startPage();
        List<SysGeneralnaireRecord> list = sysGeneralnaireRecordService.selectSysGeneralnaireRecordList(sysGeneralnaireRecord);
        return getDataTable(list);
    }



    /**
     * 导出普查结果列表
     */
    //@PreAuthorize("@ss.hasPermi('system:generalsurveyrecord:export')")
    @Log(title = "普查结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysGeneralnaireRecord sysGeneralnaireRecord)
    {
        List<SysGeneralnaireRecord> list = sysGeneralnaireRecordService.selectSysGeneralnaireRecordList(sysGeneralnaireRecord);
        ExcelUtil<SysGeneralnaireRecord> util = new ExcelUtil<SysGeneralnaireRecord>(SysGeneralnaireRecord.class);
        util.exportExcel(response, list, "普查结果数据");
    }

    /**
     * 获取普查结果详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:generalsurveyrecord:query')")
    @GetMapping(value = "/{questionId}")
    public AjaxResult getInfo(@PathVariable("questionId") Long questionId)
    {
        return AjaxResult.success(sysGeneralnaireRecordService.selectSysGeneralnaireRecordById(questionId,getLoginUser().getDeptId(),getLoginUser().getUserId()));
    }

    /**
     * 新增普查结果
     */
  //  @PreAuthorize("@ss.hasPermi('system:generalsurveyrecord:add')")
    @Log(title = "普查结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysGeneralnaireRecord sysGeneralnaireRecord)
    {
        sysGeneralnaireRecord.setCreateBy(getUsername());
        return toAjax(sysGeneralnaireRecordService.insertSysGeneralnaireRecord(sysGeneralnaireRecord));
    }

    /**
     * 修改普查结果
     */
  //  @PreAuthorize("@ss.hasPermi('system:generalsurveyrecord:edit')")
    @Log(title = "普查结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysGeneralnaireRecord sysGeneralnaireRecord)
    {
        return toAjax(sysGeneralnaireRecordService.updateSysGeneralnaireRecord(sysGeneralnaireRecord));
    }

    /**
     * 删除普查结果
     */
  //  @PreAuthorize("@ss.hasPermi('system:generalsurveyrecord:remove')")
    @Log(title = "普查结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{questionIds}")
    public AjaxResult remove(@PathVariable Long[] questionIds)
    {
        return toAjax(sysGeneralnaireRecordService.deleteSysGeneralnaireRecordByQuestionIds(questionIds));
    }
}
